<%--
  Created by IntelliJ IDEA.
  User: qjw
  Date: 2020/11/17
  Time: 17:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.springframework.context.i18n.LocaleContextHolder" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%>



<html>
<head>
    <title>Title</title>
</head>
<body>
<a href="changeLocale?locale=zh_CH">中文</a>
<a href="changeLocale?locale=en_US">English</a>
<%
    if (request.getAttribute("user") == null) {//数据可能来自上一次用户输入数据
        login.User user = new login.User();
        request.setAttribute("user", user);
    }%>

<form:form action="reg" method="POST" modelAttribute="user">
    <%--    这是一个表单--%>
    <table border="0">
        <tr>
                <%--            <td>用&nbsp;户&nbsp;名：</td>--%>

            <td><spring:message code="username"/>：</td>
            <td><form:input path="username"/>*<form:errors path="username"></form:errors></td>
        </tr>
        <tr>
                <%--            <td>密&nbsp;&nbsp;&nbsp;码：</td>--%>

            <td><spring:message code="password"/>：</td>
            <td><form:password path="password"/>*<form:errors path="password"></form:errors><form:errors
                    path="samePassword1"></form:errors></td>
        </tr>
        <tr>
                <%--            <td>确认密码：</td>--%>

            <td><spring:message code="password2"/>：</td>
            <td><form:password path="password2"/>*<form:errors path="samePassword"></form:errors></td>
        </tr>
        <tr>
                <%--            <td>性&nbsp;&nbsp;&nbsp;别：</td>--%>

            <td><spring:message code="sex"/>：</td>

            <%
                Map<String, String> genders = new HashMap<String, String>();
                String language = LocaleContextHolder.getLocale().getLanguage();
                if (language == "zh") {
                    genders.put("1", "男");
                    genders.put("0", "女");
                } else {
                    genders.put("1", "man");
                    genders.put("0", "woman");
                }
                request.setAttribute("genders", genders);
            %>
            <td><form:radiobuttons path="sex" items="${genders}" delimiter="&nbsp;"/></td>
        </tr>
        <tr>
            <%
                Map<String, String> works = new HashMap<String, String>();
                if (language == "zh") {
                    works.put("0", "学生");
                    works.put("1", "老师");
                    works.put("2", "工人");
                } else {
                    works.put("0", "students");
                    works.put("1", "The teacher");
                    works.put("2", "workers");
                }
                request.setAttribute("works", works);
            %>
                <%--            <td>职&nbsp;&nbsp;&nbsp;业：</td>--%>

            <td><spring:message code="work"/>：</td>

            <td><form:select path="work" items="${works}"/>
        </tr>
        <tr>
                <%--            <td>个人爱好：</td>--%>

            <td><spring:message code="favourite"/>：</td>

            <%
                Map<String, String> favourites = new HashMap<String, String>();
                if (language == "zh") {
                    favourites.put("0", "影视娱乐");
                    favourites.put("1", "电脑网络");
                    favourites.put("2", "棋牌娱乐");
                } else {
                    favourites.put("0", "The film and television entertainment");
                    favourites.put("1", "The computer network");
                    favourites.put("2", "Chess entertainment");
                }
                request.setAttribute("favourites", favourites);
            %>
            <td><form:checkboxes path="favorite" items="${favourites}"/></td>
        </tr>
        <tr>
                <%--            <td>个人说明：</td>--%>

            <td><spring:message code="note"/>：</td>

            <td><form:textarea path="note" rows="3" cols="30"/></td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" value=
                <spring:message code="submit"/> name="s1"/>
                &nbsp;&nbsp;&nbsp; <input type="reset" value=
                    <spring:message code="reset"/> name="s2">
            </td>
        </tr>
    </table>
</form:form>


</body>
</html>
